Acknowledge/Resolve incident via official Python client

Hi PagerDuty,

I’m using your official Python package pdpyras to read incidents and mark them as acknowledged/resolved based on a demo project I built. However, the API (both rest and Events) is always giving me a 400 error.

pdpyras.PDClientError: POST https://events.pagerduty.com/v2/enqueue: API responded with non-success status (400)

I created a Developer account. Then, I created an API key for the account. I confirmed I’m able to read incidents and grab their attributes. However, the acknowledge method is always failing for me.

self.events.acknowledge(dedup_key=incident_key) # fails
self.events.acknowledge(dedup_key=incident_id) # fails

I tried both using the incident unique key (32 hex characters string) and the incident ID (7 alphanumeric chars string).

I also searched on your package source code in GitHub in order to understand what should I pass to this method. However you’re using mocks that do not make it clear. See here.

Would you be able to assist me on what should I do after I read an incident from the API (using find method) to getting this incident being acknowledged? The documentation doesn’t seem to make it clear.

Parameters

dedup_key – The deduplication key of the alert to set to the acknowledged state.

Is it the long ID, the short one or something else?

Thanks!

Hi Joe!

The value that the acknowledge method is looking for is the dedup_key value from the original trigger event. You can view the parameters for the event payload here.

The dedup_key value is whatever value is included in the original trigger event (i.e. it is set by you, or the triggering tool). If no dedup_key is included, then the value will be randomized.

If you don’t have the dedup_key value, you can find this information by querying the log entries endpoint for a specific incident like this:

https://api.pagerduty.com/incidents/{incident-id}/log_entries?include[]=channels

You will want to include channels to get event information that contains the dedup_key!

I hope this helps! Let us know if you have any questions :slight_smile:

Best,
Josef

Do you want to send events/event updates into PagerDuty’s event API to create/acknowledge an incident or do you want to use the main REST API to manage the incident? If you use the REST API, the dedupe key isn’t needed and you can use the incident id directly to ack/resolve as needed.

Hi @dmcclure,

Thanks for your reply. I will be using the API in order to acknowledge and potentially resolve incidents from a service I’ll build. The amount is expected to be 100-300 per day. I think my best option is the Events v2 API. However, I wasn’t able to make it work. I will try again later this week with the new details shared by @JosefGoodyear.

It doesn’t make sense to me to offer a Python package where one of the required arguments can only be obtained by directly calling the API, though. Does @JosefGoodyear’s comment mean I will need to build a wrapper around that HTTP call so that I can get the dedup_key I will later use when calling self.events.acknowledge(dedup_key=dedup_key) ? That’s a bit odd.

Maybe I’m misreading the official Python package docs, but is there any way for me to find the dedup_key of an incident by using the package rather than directly invoking an HTTP endpoint? Thanks!

If you will be using your script to generate an event via Event API v2 to create the incident, then you will need to know in advance (in your code) or request via another API call the incident’s key to use for your follow on Event API v2 updates.

Where is your source data coming from? Do you have enough data from your source to create a well known unique dedup_key when creating the event trigger that you could also use for future event acknowledgement and resolution updates? You have complete control over what you set in that payload field when creating the event.

If not, you can also create PagerDuty Event Rules in a ruleset to extract fields from your event payload to derive a dedup_key value for use.